package com.example.tests;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import com.example.fw.Contacts;

public class ContactCreationTests extends TestBase {

    @Test(dataProvider = "contactsFromFile", dataProviderClass = ContactDataGenerator.class)
    public void testValidContactCanBeCreated(ContactObject validContact) {
            Contacts oldList = app.getContactHelper().getContacts();
            app.getContactHelper().createNewContact(validContact);
            Contacts newList = app.getContactHelper().getContacts();
            assertThat(newList, equalTo(oldList.withAdded(validContact)));          
    }

    @AfterMethod
    public void testUiAndDbConformWithDb() {
            if (app.getProperty("ui.check") != null) {
                    Contacts modelList = app.getContactHelper().getContacts();
                    Contacts uiList = app.getContactHelper().getUiContacts();
                    assertThat(uiList, equalTo(modelList));
            }
            if (app.getProperty("db.check") != null) {
                    Contacts modelList = app.getContactHelper().getContacts();
                    Contacts dbList = app.getHibernateHelper().getContacts();
                    assertThat(dbList, equalTo(modelList));
            }
    }

}
